/*
 ============================================================================
 Name		: MyControl.cpp
 Author	  : William Zhang
 Version	 : 1.0
 Copyright   : all rights reserved.
 Description : CMyControl implementation
 ============================================================================
 */

#include "MyControl.h"

CMyControl::CMyControl()
	{
	// No implementation required
	}

CMyControl::~CMyControl()
	{
	}

CMyControl* CMyControl::NewLC(const TRect& aRect,const CCoeControl* aParent)
	{
	CMyControl* self = new (ELeave) CMyControl();
	CleanupStack::PushL(self);
	self->ConstructL(aRect,aParent);
	return self;
	}

CMyControl* CMyControl::NewL(const TRect& aRect,const CCoeControl* aParent)
	{
	CMyControl* self = CMyControl::NewLC(aRect,aParent);
	CleanupStack::Pop(); // self;
	return self;
	}

void CMyControl::ConstructL(const TRect& aRect,const CCoeControl* aParent)
	{
	if(aParent == NULL)
		{
		CreateWindowL();
		}
	else
		{
		SetContainerWindowL(*aParent);
		}
	
	InitComponentArrayL();
	
	iLabel = new (ELeave)CEikLabel;
	iLabel->SetContainerWindowL(*this);
	iLabel->SetTextL(_L("Hello World"));
	iLabel->SetSize(TSize(100,100));
	Components().AppendLC(iLabel);
	CleanupStack::Pop(iLabel);
	
	SetRect(aRect);
//	iLabel->DrawNow();
	if(aParent == NULL)
		{
		ActivateL();
		}
	
	
	}


void CMyControl::Draw(const TRect& /* aRect */) const
	{
	CWindowGc& gc = SystemGc();
	gc.SetBrushColor(KRgbBlue);
	gc.Clear(Rect());
	}

void CMyControl::SizeChanged()
	{
    if(iLabel)
        {
        TRect rect(Rect());
//        rect.Shrink(TSize(5,2));
        iLabel->SetRect(rect);
        }
	}

TSize CMyControl::MinimumSize()
    {
    TRect rect = iLabel->MinimumSize();
    rect.Grow(TSize(5,5));
    return rect.Size();    
    }

void CMyControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{
    iLabel->SetSize(TSize(iLabel->Size().iHeight+5,iLabel->Size().iWidth+5));
	iLabel->SetRect(TSize(150,100));
	iLabel->DrawNow();
	DrawNow();
	}
